#include<iostream>
using namespace std;
<<<<<<< HEAD

int main() {
    int n;
    cin >> n;
    int a[105];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    // 找到最大值和最小值的位置
    int max_pos = 0, min_pos = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > a[max_pos]) {
            max_pos = i;
        }
        if (a[i] <= a[min_pos]) {
            min_pos = i;
        }
    }
    
    // 计算移动步数
    int ans = max_pos + (n - 1 - min_pos);
    
    // 如果最大值在最小值右边，会少一步（因为最大值左移时会让最小值右移）
    if (max_pos > min_pos) {
        ans--;
    }
    
    cout << ans << endl;
    
=======
int n;
int a[114514];
int tong[114514];
int c = 0;
int main()
{
    cin >> n;
    for (int i = 0;i < n;++i)
    {
        cin >> a[i];
        tong[a[i]]++;
    }
    for (int i = 1;i <= n;++i)
    {
        if (tong[i] >= 2)
        {
            c += (tong[i] - 1 * tong[i] / 2 * (n - tong[i]));
        }
    }
    cout << c;
>>>>>>> refs/remotes/origin/master
    return 0;
}